/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Ventana_Mov.java
 *
 * Created on 10-abr-2013, 11:57:28
 */
package jumavidesktop.GUI.Principal;

import java.awt.Dimension;
import java.awt.Image;
import java.net.URL;
import java.text.DateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import jumavidesktop.Manejadores.Intefaces.INotificadoMatricula;
import jumavidesktop.Persistencia.entidades.Movimientos;

/**
 *
 * @author kjh
 */
public class Ventana_Mov extends javax.swing.JInternalFrame implements INotificadoMatricula{
    Movimientos mov;
    ImageIcon icon;
    /** Creates new form Ventana_Mov */
    public Ventana_Mov() {
        super("Último movimiento");
        initComponents();
        this.setVisible(true);
        quitarIconos();        
    }
    
    public Ventana_Mov(Dimension a){
        this();
        this.setSize(a);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pan_Interno = new javax.swing.JPanel();
        panel_Sup = new javax.swing.JPanel();
        label_foto = new javax.swing.JLabel();
        panel_Inf = new javax.swing.JPanel();
        panel_Cam = new javax.swing.JPanel();
        label_Cam = new javax.swing.JLabel();
        label_CamV = new javax.swing.JLabel();
        panel_Mat = new javax.swing.JPanel();
        label_Mat = new javax.swing.JLabel();
        label_MatV = new javax.swing.JLabel();
        panel_Hora = new javax.swing.JPanel();
        label_Hora = new javax.swing.JLabel();
        label_HoraV = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                formComponentResized(evt);
            }
        });

        pan_Interno.setPreferredSize(new java.awt.Dimension(350, 350));

        panel_Sup.setLayout(new java.awt.BorderLayout());

        label_foto.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        label_foto.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        panel_Sup.add(label_foto, java.awt.BorderLayout.CENTER);

        panel_Inf.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        panel_Inf.setLayout(new javax.swing.BoxLayout(panel_Inf, javax.swing.BoxLayout.X_AXIS));

        panel_Cam.setLayout(new java.awt.BorderLayout());

        label_Cam.setFont(new java.awt.Font("Tahoma", 1, 14));
        label_Cam.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        label_Cam.setText("Cámara");
        panel_Cam.add(label_Cam, java.awt.BorderLayout.NORTH);

        label_CamV.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        panel_Cam.add(label_CamV, java.awt.BorderLayout.CENTER);

        panel_Inf.add(panel_Cam);

        panel_Mat.setLayout(new java.awt.BorderLayout());

        label_Mat.setFont(new java.awt.Font("Tahoma", 1, 14));
        label_Mat.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        label_Mat.setText("Matrícula");
        panel_Mat.add(label_Mat, java.awt.BorderLayout.PAGE_START);

        label_MatV.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        panel_Mat.add(label_MatV, java.awt.BorderLayout.CENTER);

        panel_Inf.add(panel_Mat);

        panel_Hora.setLayout(new java.awt.BorderLayout());

        label_Hora.setFont(new java.awt.Font("Tahoma", 1, 14));
        label_Hora.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        label_Hora.setText("Fecha y Hora");
        panel_Hora.add(label_Hora, java.awt.BorderLayout.PAGE_START);

        label_HoraV.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        panel_Hora.add(label_HoraV, java.awt.BorderLayout.CENTER);

        panel_Inf.add(panel_Hora);

        javax.swing.GroupLayout pan_InternoLayout = new javax.swing.GroupLayout(pan_Interno);
        pan_Interno.setLayout(pan_InternoLayout);
        pan_InternoLayout.setHorizontalGroup(
            pan_InternoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 392, Short.MAX_VALUE)
            .addGroup(pan_InternoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(panel_Inf, javax.swing.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE))
            .addGroup(pan_InternoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(panel_Sup, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE))
        );
        pan_InternoLayout.setVerticalGroup(
            pan_InternoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 349, Short.MAX_VALUE)
            .addGroup(pan_InternoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pan_InternoLayout.createSequentialGroup()
                    .addContainerGap(280, Short.MAX_VALUE)
                    .addComponent(panel_Inf, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addGroup(pan_InternoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(pan_InternoLayout.createSequentialGroup()
                    .addComponent(panel_Sup, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(80, Short.MAX_VALUE)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 392, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(pan_Interno, javax.swing.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 349, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(pan_Interno, javax.swing.GroupLayout.DEFAULT_SIZE, 349, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
    revalidate();
    repaint();
    label_foto.setIcon(escalarImagen(icon,this.getWidth(),this.getHeight()-panel_Inf.getHeight()));
}//GEN-LAST:event_formComponentResized

    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel label_Cam;
    private javax.swing.JLabel label_CamV;
    private javax.swing.JLabel label_Hora;
    private javax.swing.JLabel label_HoraV;
    private javax.swing.JLabel label_Mat;
    private javax.swing.JLabel label_MatV;
    private javax.swing.JLabel label_foto;
    private javax.swing.JPanel pan_Interno;
    private javax.swing.JPanel panel_Cam;
    private javax.swing.JPanel panel_Hora;
    private javax.swing.JPanel panel_Inf;
    private javax.swing.JPanel panel_Mat;
    private javax.swing.JPanel panel_Sup;
    // End of variables declaration//GEN-END:variables

    @Override
    public void detectadaMatricula(Movimientos mv) {
        try {
            this.mov=mv;
            setMovimientos();
        } catch (Exception ex) {
            Logger.getLogger(Ventana_Mov.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void setMovimientos() throws Exception{
      setCamara();
      setHora();
      setMat();
      setFoto();
    }
    
    private void quitarIconos(){
        this.setIconifiable(false);
        this.setMaximizable(false);
        this.setClosable(false);
        this.setResizable(false);
        this.setVisible(true);
    }
    
    private void setCamara(){
        label_CamV.setText(mov.getCamaraid().getId().toString());

    }
    
    private void setHora(){
        
        label_HoraV.setText(DateFormat.getInstance().format(mov.getFechaYHora()));
    }
    
    private void setMat(){
        label_MatV.setText(mov.getMatricula().getMatricula());
        
    }
    
    private void setFoto() throws Exception{
        ImageIcon icono = new ImageIcon(mov.getFoto());  
        ImageIcon icon2 = escalarImagen(icono,label_foto.getWidth(),label_foto.getHeight());  
        label_foto.setIcon(icon2);
    }
    
    private ImageIcon escalarImagen(ImageIcon path, int ancho, int alto){
        if(path!=null){
            Image img = path.getImage();
            Image otraimg = img.getScaledInstance(ancho,alto, Image.SCALE_SMOOTH);
            ImageIcon otroicon = new ImageIcon(otraimg);
            return otroicon;
        }
        return null;
    }
}


